package org.marsdonne.auth.wechat;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.http.HttpEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import java.util.LinkedHashMap;
import java.util.Map;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class QrCodeRequest {
    private String token;
    private String scene;
    private String page;
    private Boolean checkPath;
    private String envVersion;
    private Integer width;
    private Boolean autoColor;
    private JsonNode lineColor;
    private Boolean hyaline;

    public QrCodeRequest(String token, String scene) {
        this.token = token;
        this.scene = scene;
    }

    public QrCodeRequest(String token, String scene, String page, Boolean checkPath, String envVersion) {
        this(token, scene);
        this.page = page;
        this.checkPath = checkPath;
        this.envVersion = envVersion;
    }

    public Map<String, Object> toMap() {
        if(scene.length() > 32)
            throw new RuntimeException("The scene is too long");
        return new LinkedHashMap<String, Object>() {{
            put("scene", scene);
            if (page != null)
                put("page", page);
            if (checkPath != null)
                put("check_path", checkPath);
            if (envVersion != null)
                put("env_version", envVersion);
            if (width != null)
                put("width", width);
            if (autoColor != null)
                put("auto_color", autoColor);
            if (lineColor != null)
                put("line_color", lineColor);
            if (hyaline != null)
                put("is_hyaline", hyaline);
        }};
    }
}
